﻿@model CooWork.Models.TaskListContainerViewModel
@using MvcContrib.UI.Grid;
@using CooWork.Models;
@using CooWork.Core;



<script type="text/javascript" >
    function expand(i) {

        var oc=$("#tr_" + i + " span").eq(0).attr("class").toString();

        if (oc == "tasktree-icon-closed") {
            $.ajax({
                url: "/Task/GetList",
                data: "id=" + i,
                success: function (data) {
                    // alert(JSON.stringify(data));
                    var newrow = "";
                    $.each(data, function (i, item) {
                        newrow += "<tr class=\"appendtr\" style=\"background-color:#CCFFCC\" id=\"tr_" + data[i].ID + "\" ><td></td><td>     <input type=\"checkbox\" autocomplete=\"off\" name=\"selected\" value=\"1\" /></td><td><a href='/Task/Details?ID="+data[i].ID+"'>"
                         + data[i].ID + "</a></td><td><div id=\"action_"
                         + data[i].ID + "\" onclick=\"showPanel("
                         + data[i].ID + ")\" class=\"draggable sprite-menu\"  style=\"width:20px;height:18px;cursor:pointer;\" ></div></td>"
                         + "<td><div class=\"level_"
                         + data[i].depth + "\" >"
                         + N(data[i].Description) + "</div></td><td>"
                         + N(data[i].Owner) + "</td><td>"
                         + N(data[i].StatusId) + "</td><td>"
                         + timeformat(data[i].CreateTime) + "</td><td>"
                         + N(data[i].Estimate) + "</td><td>"
                         + N(data[i].Remaining) + "</td><td>"
                         + N(data[i].severity) + "</td><td>"
                         + N(data[i].priority) + "</td>"
                         + "</tr>";
                    });

                    $("#tr_" + i).after(newrow);
                    $("#tr_" + i + " span").eq(0).removeClass("tasktree-icon-closed").addClass("tasktree-icon-opened");
                    //alert(newrow);

                },
                error: function () {

                }
            });
        }
        else if (oc = "tasktree-icon-opened") {
            $(".appendtr").remove();           
            $("#tr_" + i + " span").eq(0).removeClass("tasktree-icon-opened").addClass("tasktree-icon-closed");
        }



    }


    $(function () {
        $("#taskOwner").click(function () {
            if ($("#demo2").is(':visible')) {
                $("#demo2").hide();
            }
            else {
                $("#demo2").show();
            }
            $("#taskOwner").parent("label").append($("#demo2"));
            $("#taskOwnerHidden").val("");
        });

        $("#demo2").hide();
        $("#demo2").jstree({
            "json_data": {
                "ajax": {
                    "url": "/data/totalOrg",
                    "data": function (n) {
                    }
                }
            },
            "plugins": ["themes", "json_data", "ui"]
		, "core": { "initially_open": "department_1", "animation": 0 }
        }).bind("select_node.jstree", function (e, data) {

         //   alert(data.rslt.obj.attr("tag"));

            if (data.rslt.obj.attr("tag").toString().indexOf("department") >= 0) {
                return;
            }

            $("#taskOwner").val($.trim(data.rslt.obj.find("a").eq(0).text().toString()));
            $("#taskOwnerHidden").val($.trim(data.rslt.obj.attr("tag").toString()));
            $("#demo2").hide();
        });
    });
</script>
      

 <table id="tasklist" class="listing">
    <tr>
       <th class="cursor"></th>
<th class="handle">
<input id="select_all" type="checkbox" value="1" onclick="taskList.selectAll(this.checked);" name="select_all" autocomplete="off" />
</th>
<th style="width:43px;">No.</th>
       <th style="width:43px;">
           操作
        </th>

        <th>
            Description
        </th>
      
   
        <th style="width:83px;">
            Owner
        </th>
        <th style="width:63px;">
            StatusId
        </th>
        <th style="width:83px;">
            CreateTime
        </th>
        <th style="width:63px;">
            Estimate
        </th>
        <th style="width:63px;">
            Remaining
        </th>
        <th style="width:63px;">
            重要性
        </th>
        <th style="width:63px;">
            紧迫性
        </th>
    </tr>


<tr id="new_form_row" class="nohover"><td class="new_form_space"></td>
<td colspan="2" class="new_form_space"><div id="EditId" style="padding-left:24px;padding-top:10px;"></div>
</td><td colspan="9" id="new_form_col" class="new_form_col_0"><div style="" id="new_task_form">
           


<div style="margin:0;padding:0;display:inline">

</div>


<label class="textarea" for="task_description">
    <span>Description</span>
    <textarea style="width:98%" rows="5" name="task[description]" id="task_description" cols="45"></textarea>
</label>


<label for="task_status" class="nowrap">
    任务状态:
    <select name="task[status]" id="task_status"><option value="1">Not Started</option>
<option value="2">In Progress</option>
<option value="3">Reopened</option>
<option value="4">Blocked</option>
<option value="5">Completed</option>
<option value="6">Verified</option>
<option value="7">Duplicate</option>
<option value="8">Will Not Do</option></select>
</label>


优先级：<label for="taskPriority" class="nowrap" >    
  @Html.Action("ddlpriority", "Data", new { id = "1", name = "taskPriority" })
 </label>

 重要性：<label for="taskSeverity" class="nowrap" >    
  @Html.Action("ddlseverity", "Data", new { id = "1", name = "taskSeverity" })
 </label>

 
 <br />



<label for="task_parent" class="nowrap">
    上一级任务编号:
      <input type="text" value="" name="task_parentid" id="task_parentid" class="size6"  />
   
   
</label>

<label for="task_estimate" class="nowrap">
   预计耗时(天):
    <input type="text" value="" name="task[estimate]" id="task_estimate"  class="size6" />
</label>


<label for="task_owner_id" class="nowrap" style="position:absolute;">    
    负责人:
    <input type="text"  id="taskOwner" name="task[Owner]" value="" />
    <input type="hidden" id="taskOwnerHidden" value="" />
    <div id="demo2" class="demo"></div>


</label>

<br />


<!--[eoform:task]-->

<div class ="newtask-buttonrow">
        <input type ="button" value ="Save"  id ="new_task_save" class ="small_btn" />
        <input type ="button" value ="Cancel" id ="new_task_cancel" class ="small_btn" />     
     
</div>

        <div class ="hidden" id ="new_task_form_more">


    <div class ="clear"></div >
   
    <label class ="textarea" for ="task_wiki">
        <span> Wiki </span >
        <textarea style ="width :98%" rows ="6" name ="task[wiki]" id ="task_wiki" cols ="45"></textarea>
    </label>


    <div class ="new_task_relationships">
        <label class ="fixed" for ="task_related">
            <span class ="label">Related Tasks: </span>
            <input type ="text" autocapitalize ="off" autocorrect ="off" value ="" name ="task[related]" id ="task_related" />
        </label>
        <label class ="fixed" for ="task_duplicate">
            <span class ="label">Duplicate Tasks: </span>
            <input type ="text" autocapitalize ="off" autocorrect ="off" value ="" name ="task[duplicate]" id ="task_duplicate" />
        </label>
        <div class ="clear"></div >
       
               
            </div>

    <div class ="clear"></div >
    <div class ="newtask-buttonrow">
        <input type ="button" value ="Save" onclick ="newTask.save(); return false;" class ="small_btn" />
        <input type ="button" value ="Cancel" onclick ="newTask.cancel(); return false;" class ="small_btn" />
    </div>
</div>


<input type ="hidden" value ="2891231" id ="insert_after" name ="insert_after"><input type="hidden" value ="2891231" id ="task_sibling_id" name ="task[sibling_id]"><input type ="hidden" value ="0" id ="insert_level" name ="insert_level">

    </div></td ></tr >



@foreach (var item in Model.TaskPagedList)
{
    <tr id="tr_@(item.ID)">
        <td> @*
            @Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
            @Html.ActionLink("Details", "Details", new { id=item.ID }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.ID }) *@        </td>
     
        <td id="checkbox_handle_2891226" class="handle" onclick="taskActions.toggleTaskCheckbox(2891226, event)">
        <input id="checkbox_2891226" type="checkbox" autocomplete="off" name="selected" value="1" />
        </td>
        <td><a href="/Task/Details?ID=@(item.ID)" >@(item.ID)</a></td>

        <td>   
           
            <div id="action_@(item.ID)" onclick="showPanel(@(item.ID))" class="draggable sprite-menu" style="width:20px;height:18px;cursor:pointer;" >
      
       </div></td>


        <td>
         


                 <div >        
                 @{  if (item.CooTask1.Count > 0)
                     {
                   <span class="tasktree-icon-closed" onclick="expand(@(item.ID));"  >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> 
                     }
                  }

                                  <div style="float:left;" class="taskdesc" > <span class="tags">@item.tags</span>    @Html.Raw(StringFunc.HtmlAreaEncode(item.Description))  </div>
                 <label id="comment_@(item.ID)" style="float:left;">
                  @{
                        if (item.CooTaskComments.Count > 0)
                        {
                            if (item.CooTaskComments.Count == 1)
                            {
                               <i>(1 comment)</i>
                            }
                            else
                            {
                               <i>(@(item.CooTaskComments.Count) comments)</i>
                            }
                        }
                   }
                 </label></div>
        </td>
 
 
        <td>
                                                 @(CacheSet.U2N(item.Owner))
        </td>
        <td>
                                                 @(CacheSet.StatusCache[item.StatusId.Value])
        </td>
        <td>
                                                 @String.Format("{0:g}", item.CreateTime)
        </td>
        <td>
                                                 @item.Estimate
        </td>
        <td>
                                                 @item.Remaining
        </td>
       <td>
                  @CacheSet.Severity2N(item.severity.Value)
       </td>
       <td>
                  @CacheSet.Priority2N(item.priority.Value)
       </td>
  
    </tr>
}




<tfoot id ="sprint_totals">
<tr>
    <th class ="cursor">
    </th><th class ="handle">
    </th><th class ="popup">
    </th><th colspan ="2">
            <input type ="button" value ="New Task" style =""  id ="show_hide_new_task2" class ="small_btn bottom_newtask_btn">
   
    </th>
    <th class ="r" colspan ="2">Total: </th>
   
    <th id ="sprint_total_estimate" class ="estimate"> 27</th >
    <th id ="sprint_total_remaining" class ="remaining"> 16</th >
    <th colspan="3"></th >
</tr>

</tfoot>
</table>

